package _20250304;

public class MyThread2 {
    /**
     * 题目：编写程序启动三个线程，每个线程打印自己的线程名 5 次。
     */
    public static void main(String[] args) {
        int i=0;
        Thread printMyName = new Thread(new PrintMyName(),"printMyName"+i );
        Thread printMyName2 = new Thread(new PrintMyName() ,"printMyName2 ");
        Thread printMyName3 = new Thread(new PrintMyName() ,"printMyName3");
        printMyName.start();
        printMyName2.start();
        printMyName3.start();
    }
    private static class PrintMyName implements Runnable {

        @Override
        public synchronized void run() {
            for (int i = 0; i < 5; i++) {
                System.out.println(Thread.currentThread().getName());
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
            }
        }
    }

}
